package com.shop.domain.admin;

import com.alibaba.fastjson.annotation.JSONField;
import com.shop.common.enums.admin.AdminLockEnum;
import com.shop.jpa.domain.BaseDomain;
import com.shop.jpa.support.JpaConst;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * <p>Admin 实体类</p>
 * <p>Table: admin - 用户表</p>
 *
 * @author Jerry
 */
@ApiModel("Admin 实体类")
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "t_admin")
@SQLDelete(sql = "update t_admin set is_deleted = 1 where id = ?")
@Where(clause = JpaConst.WHERE_CLAUSE_NOT_DELETED)
@DynamicInsert(true)
@DynamicUpdate(true)
public class Admin extends BaseDomain implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty(value = "id", hidden = true)
    @Column(name = "id")
    @JSONField(serialize=false)
    private Long id;

    /**
     * 登录名
     */
    @ApiModelProperty("登录名")
    @Column(name = "name")
    private String name;

    /**
     * 密码
     */
    @ApiModelProperty(value = "密码", hidden = true)
    @Column(name = "pwd")
    @JSONField(serialize = false)
    private String pwd;

    /**
     * mobile
     */
    @ApiModelProperty("手机号")
    @Column(name = "mobile")
    private String mobile;

    /**
     * 真实姓名
     */
    @ApiModelProperty("真实姓名")
    @Column(name = "reality_name")
    private String realityName;

    /**
     * 身份证号
     */
    @ApiModelProperty("身份证号")
    @Column(name = "id_number")
    private String idNumber;

    /**
     * 锁定类型 0 未锁定 1 管理员锁定 2 密码错误次数过多锁定
     */
    @Column(name = "lock_type")
    private Integer lockType;

    /**
     * 邮箱
     */
    @ApiModelProperty("邮箱")
    @Column(name = "email")
    private String email;

    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 修改时间
     */
    @Column(name = "update_time")
    @JSONField(serialize = false)
    private Date updateTime;

    /**
     * 是否删除 0 否 1 是
     */
    @Column(name = "is_deleted")
    @JSONField(serialize = false)
    private Integer isDeleted;

    @Transient
    private String lockTypeStr;
    public String getLockTypeStr() {
        return AdminLockEnum.val(this.lockType).getMsg();
    }
}